package com.arm.controller;

import com.arm.tools.AliUploadTools;
import com.arm.tools.FileTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Baggio on 2018-6-22.
 */
public class BaseController {

    @Autowired
  protected   HttpServletRequest httpServletRequest;
    @Autowired
    protected     HttpServletResponse httpServletResponse;
    @Autowired
    protected  HttpSession session;


    protected final static Logger logger = LoggerFactory.getLogger(BaseController.class);




  protected Map<String, String> showRequestParameters(HttpServletRequest request) {

    Enumeration<?> paramNames = request.getParameterNames();
    Map<String, String> map = new HashMap<String, String>();
    while (paramNames.hasMoreElements()) {

      String paramName = paramNames.nextElement().toString();
      String paramValue = request.getParameter(paramName);
      map.put(paramName, paramValue);
      System.out.println(paramName + "[:]" + paramValue);
    }



    return map;
  }



  protected String upLoadFile(InputStream inputStream, String filePath) throws Exception {
    filePath += FileTools.getUniquenessName("") + FileTools.PICTURE_SUFFIX_JPG;

    AliUploadTools.AliUploadInputStream(inputStream, true, filePath);
    filePath = AliUploadTools.PICURLADDRESS + filePath;
    return filePath;
  }


}
